// 判断是否有交集
function hasCombin(arr1, arr2) {
    let set2 = new Set(arr2);
    return arr1.some(item => set2.has(item))
    // has 可以替换成 includes
}

console.log(hasCombin([1, 2, 3], [1, 5]))



// 找到交集
function getCombin(arr1 = [], arr2) {
    let set2 = new Set(arr2);
    return arr1.filter(item => set2.has(item))
    // arr1.filter(item => arr2.includes(item))
}


// 多个区间的交集 两个数组的交集  多个数组的交集 加入set 可以去重
[[1, 2], [1, 2]]
function conbinArr(arr) {
    return arr.reduce((a, b) => a.filter(c => b.includes(c))) // [4]
}

console.log(getCombin([1, 2, 3], [1, 2]))


function findUnio(arr1, arr2) {
    arr1.sort((a, b) => a - b)
    arr2.sort((a, b) => a - b)
    let result = [];
    let l1 = 0;
    let l2 = 0;
    while (l1 < arr1.length && l2 < arr2.length) {
        if (arr1[l1] === arr2[l2]) {
            result.push(arr1[l1])
            l1++
            l2++
        }
        if (arr1[l1] < arr2[l2]) {
            l1++
        }
        if (arr1[l1] > arr2[l2]) {
            l2++
        }
    }

    return result
}